package product;

import cn.yunhe.service.ProductService;
import cn.yunhe.util.Paganation;
import org.junit.Before;
import org.junit.Test;

public class Demo {
    ProductService productService=null;
    @Before
    public void init(){
        productService=new ProductService();
    }

    /**
     * 获取  所有商品
     */
    @Test
    public void getAllProduct(){
        Paganation<Product> paganation= productService.getAllProduct(2);
        for (Product product:paganation.getItems()){
            System.out.println("商品名："+product.getProductname()+"类型："+product.getChildType().getCtypename()+"价格："+product.getPrice());
        }
        System.out.println(paganation.getPageNo());
    }

    /**
     * 获取某个商品的详情
     */
    @Test
    public void getProduct(){
        Product product=productService.getProduct(2);
        System.out.println("商品名称："+product.getProductname()+"  商品属性名:"+product.getChildType().getCtypename());
    }

    @Test
    public void updateProduct(){
        Product product=new Product();
        product.setProductname("欧珀莱均衡保湿五件套");
        product.setProductid(2);
        product.setBrand("德芙");
        product.setPic("2.jpg");
        product.setPrice(99.9);
       boolean flag=productService.updateProduct(product);
        System.out.println(flag);
    }
    @Test
    public void deleteProduct(){
        ProductService productService=new ProductService();
        boolean flag=productService.deleteProduct(20);
        if (flag){
            System.out.println("删除成功");
        }
    }



}
